/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ships.core;

import java.lang.reflect.Array;

/**
 *
 * @author fqhuy
 */
public class SimpleHostDataBuffer<E extends Number> extends HostDataBuffer<E> {

    private E[] data;
    private E[] dataAll[];

    public SimpleHostDataBuffer(Class<E> cls) {
        super(cls);
    }

    public SimpleHostDataBuffer(int size, Class<E> cls) {
        super(size, cls);
        dataAll = (E[][]) Array.newInstance(cls, 1, size);
        data = dataAll[0];
    }

    public SimpleHostDataBuffer(int size, int numBanks, Class<E> cls) {
        super(size, numBanks, cls);
        dataAll = (E[][]) Array.newInstance(cls, numBanks, size);
        data = dataAll[0];
    }

    @Override
    public E getElem(int i) {
        return data[i];
    }

    @Override
    public E getElem(int bank, int i) {
        return dataAll[bank][i];
    }

    @Override
    public void setElem(int i, E val) {
        data[i] = val;
    }

    @Override
    public void setElem(int bank, int i, E val) {
        dataAll[bank][i] = val;
    }
}
